home *** CD-ROM | disk | FTP | other *** search
- Path: dagwood.cs.ucsb.edu!not-for-mail
- From: schapel@cs.ucsb.edu (Steve E. Chapel)
- Newsgroups: comp.lang.c
- Subject: Re: char* string problem
- Date: 5 Jan 1996 11:54:52 -0800
- Organization: Computer Science, UCSB
- Message-ID: <4cjvmc$1eq@dagwood.cs.ucsb.edu>
- References: <4ci7gu$68r@cloner3.netcom.com>
- NNTP-Posting-Host: dagwood.cs.ucsb.edu
-
- tstevens@ix.netcom.com (Edward Stevens ) writes:
-
- > I need to prepend some switch characters to some strings passed
- >to a main program which I have renamed for use as a function.
-
- >The calling program looks like this:
-
- >char* the_args[4];
- >char* Aprefix = " -A";
- >char* Bprefix = " -B";
- >char* CPrefix = " -C";
- >char* Dprexix = " -D";
-
- >the_args[0] = "user_name";
- >the_args[0] = strcat(Aprefix,the_args[0]);
-
- Okay, you're putting "user_name" after the string " -A". But the string
- " -A" is stored in a location where there is no guarantee what comes after
- it, or that you can write into that space. How about something like:
-
- char temp[80]; /* Plenty of space you can do anything with */
- strcpy(temp, Aprefix);
- strcat(temp, the_args[0]);
-
- By defining temp as an array, you get to do whatever you like with it.
- --
- Steve Chapel schapel@cs.ucsb.edu | http://www.cs.ucsb.edu/~schapel
- Senior in Computer Science at the | Check out my updated web page!!
- University of California, Santa Barbara | finger -l schapel@eci1.ucsb.edu
- "I jumped, O my brothers, and I fell hard, but I did not snuff it." - Alex
-